//
//  DetailViewController.swift
//  DeckTracker
//
//  Created by YJH on 2025/5/5.
//

import UIKit
import SnapKit

// 定义卡片项结构体
struct CardItem {
    let text: String
    let imageName: String
}

class DetailViewController: UIViewController {
    
    // 用于接收从 ListViewController 传递过来的列表项
    var selectedListItem: ListItem?
    
    // 懒加载卡片图片视图
    lazy var cardImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let titleLabel = UILabel()
        titleLabel.textColor = .white
        titleLabel.font = .systemFont(ofSize: 16, weight: .medium)
        navigationItem.titleView = titleLabel
        view.backgroundColor = .black
        
        view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handle(gr:))))
        
        // 根据传递过来的数据设置标题和图片
        if let item = selectedListItem {
            titleLabel.text = item.text
            if let image = UIImage(named: item.imageName) {
                cardImageView.image = image
            }
        }
        
        view.addSubview(cardImageView)
        cardImageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    @objc private func handle(gr: UITapGestureRecognizer) {
        navigationController?.popViewController(animated: true)
    }
}
